#include "stdafx.h"
#include ".\serversessionmanager.h"
#include "ServerSession.h"
#include <Macro.h>

ServerSessionManager::ServerSessionManager()
{
}

ServerSessionManager::~ServerSessionManager()
{
}

VOID ServerSessionManager::AddServer( ServerSession * pServer )
{
	ASSERT( FindServer( pServer->GetSessionIndex() ) == NULL );

	m_mapSessions.insert( SERVER_SESSION_PAIR( pServer->GetSessionIndex(), pServer ) );
}

ServerSession *	ServerSessionManager::FindServer( DWORD dwSessionIndex )
{
	SERVER_SESSION_MAP_ITER it = m_mapSessions.find( dwSessionIndex );

	if( it == m_mapSessions.end() ) return NULL;

	return it->second;
}

VOID ServerSessionManager::RemoveServer( DWORD dwSessionIndex )
{
#ifdef _DEBUG
	SERVER_SESSION_MAP_ITER it = m_mapSessions.find( dwSessionIndex );
	ASSERT( it != m_mapSessions.end() );
#endif

	m_mapSessions.erase( dwSessionIndex );
}

VOID ServerSessionManager::Update()
{
	SERVER_SESSION_MAP_ITER it;

	for( it = m_mapSessions.begin(); it != m_mapSessions.end(); ++it )
	{
		it->second->Update();
	}
}